package com.zt.controller;

import com.zt.anno.LogOperation;
import com.zt.pojo.Clazz;
import com.zt.pojo.ClazzQuery;
import com.zt.pojo.PageResult;
import com.zt.pojo.Result;
import com.zt.service.ClazzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    //添加班级
    @PostMapping
    @LogOperation
    public Result add(@RequestBody Clazz clazz){
        clazzService.add(clazz);
        return Result.success();
    }
    //查询所有班级
    @GetMapping("/list")
    public Result findAll(){
        List<Clazz> clazzlist = clazzService.findAll();
        return Result.success(clazzlist);
    }
    //分页查询班级
    @GetMapping
    public Result QueryPage(ClazzQuery clazzQuery){
        PageResult pageResult = clazzService.QueryPage(clazzQuery);
        return Result.success(pageResult);
    }
    //根据id删除班级
    @LogOperation
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id){
        clazzService.deleteById(id);
        return Result.success();
    }
    //根据id查询班级
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        Clazz clazz = clazzService.findById(id);
        return Result.success(clazz);
    }
    //修改班级
    @LogOperation
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return Result.success();
    }

}
